package com.hubei.service.impl;

import com.hubei.dao.UserDao;
import com.hubei.service.UserService;
import com.hubei.vo.Users;

import java.util.List;

public class UserServiceImpl implements UserService {
    private static UserServiceImpl instance;

    private UserDao userDao = UserDao.getInstance();



    @Override
    public Users userLogin(Users users) {
        // 调用DAO层的方法进行登录验证
        System.out.println("执行了登入操作");
        return userDao.userLogin(users);
    }

    @Override
    public List<Users> queryUserList(String username) {

        if(username!=null&&!"".equals(username))
        {
            username="%"+username+"%";
        }
         return  userDao.queryUserList(username);
    }
    @Override
    public int insertUser(Users users) {
        int rows = 0;
        // 新增id是没有值的，更新id是有值
        if (users.getId()==null){
            rows = userDao.insertUser(users);
        }else {
            rows = userDao.updateUser(users);
        }
        return rows;
    }

    @Override
    public int deleteUser(String id) {
        return userDao.deleteUser(id);
    }

    @Override
    public int updateUser(Users users) {
        return userDao.updateUser(users);
    }

    @Override
    public Users queryUserById(String id) {
        return userDao.queryUserById(id);
    }
}